<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
{{--    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">--}}
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <style>
        .main{
            width: 75%;
            margin: 0 auto;
            margin-top: 200px;

            color: #fff;
        }
        body{
            background-color: #fff;
        }
        .center{
            width: 40%;
            margin: 0 auto;
            background-color: #007bff;
            border-radius: 10px;
            padding-top: 30px;
            text-align: center;
            padding-bottom: 88px;
        }
        .left{
            position: absolute;
            top: 120px;
        }
        .right{
            position: absolute;
            right: 150px;
            top: 120px;
        }
        .inputbox{
            width: 87%;
            height:40px;
            background-color: #fff;
            line-height: 40px;
            margin: 0 auto 15px
        }
    </style>
</head>
<body>
    <div class="main">
        <div class="left"><img src="https://cimg.axureshop.com/0c/80/2b/0c802be68f9542098907c07ef7848723/images/登录_1/u4321.svg"></div>
        <div class="center">
            <div style="text-align: center;font-size: 40px;margin-bottom: 10px;font-family: 华文新魏">登录</div>
            <div style="text-align: center;font-size: 20px ;margin-bottom: 48px">七尾医疗服务后台管理系统</div>
            <form style="text-align: center;width: 60%;margin:0 auto;" id="f1">
                @csrf
                <div class="inputbox">
                    <label style="margin-right: 10px;font-family: 华文楷体;font-size: 16px;color: black">账号</label>
                    <input type="text" name="username" style="color: black;border: none;height: 95%;border-radius: 10px" placeholder="请输入账号" class="username">
                </div>
                <div class="inputbox">
                    <label style="margin-right: 10px;font-family: 华文楷体;font-size: 16px;color: black">密码</label>
                    <input type="password" name="password" style="color: black; border: none;height: 95%;border-radius: 10px" placeholder="请输入密码" class="password">
                </div>
                <div class="inputbox">
                    <div id="c1" style="margin: 0 auto"></div>
                    <input type="hidden" name="tokens" id="tokens">
                </div>
                <div style="text-align: right;margin-bottom: 30px">忘记密码请联系管理员</div>
                <button style="width: 100%;text-align: center;height: 48px;line-height: 48px;background-color: orange;border-radius: 10px;border: 1px solid orange;" class="sub">登录</button>
            </form>
        </div>
        <div class="main">
            <div class="right">
                <img src="https://cimg.axureshop.com/0c/80/2b/0c802be68f9542098907c07ef7848723/images/登录_1/u4322.svg">
            </div>
        </div>
    </div>
</body>
</html>
<script src="https://cdn.dingxiang-inc.com/ctu-group/captcha-ui/index.js" crossorigin="anonymous" id="dx-captcha-script"></script>
<script>
    Dcat.ready(function() {
        // ajax表单提交
        $('#login-form').form({
            validate: true,
        });
    });
    var myCaptcha = _dx.Captcha(document.getElementById('c1'), {
        appId: '97c9d6a80402d15979c17af48b4a41c0', //appId，在控制台应用管理或应用配置模块获取
        apiServer: 'https://cap.dingxiang-inc.com',
        // apiServer域名地址在控制台页面->无感验证->应用管页面左上角获取，必须填写完整包括https://。
        style:'inline',
        success: function (token) {
            $('#tokens').val(token);
            // console.log('token:', token)
            // 获取验证码token，用于后端校验，注意获取token若是sl开头的字符串，则是前端网络不通生成的降级token,请检查前端网络及apiServer地址。
        }
    })

    $(function () {
        //  1.监听表单的提交事件
        $('#f1').on('submit', function (e) {
            e.preventDefault()
            var username = $('.username').val();
            var password = $('.password').val();
            var captcha = $('#tokens').val();
            if (captcha == ""){
                alert("请验证身份信息");
                return false;
            }
            $.ajax({
                type:'POST',
                url:'login',
                data:{
                    username:username,
                    password:password,
                    captcha:captcha
                },
                dataType:'json',
                success: function(res) {
                    if (res.status){
                        window.location.href=res.data.then.value;
                    }else{
                        alert(res.errors.username);
                    }
                }
            })
        })
    })
</script>
